package net.edu_soft.ec.common.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig  {
    @Bean
    public FilterRegistrationBean registFilter() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new LogCostFilter());
        registration.addUrlPatterns("/*");
        registration.setName("LogCostFilter");
        registration.setOrder(1);
        return registration;
    }
    /**
     * 前后端跨域
     * @return
     */
//    @Bean
//    public WebMvcConfigurer webMvcConfigurer2(){
//        return new WebMvcConfigurer() {
//            /**
//             * 设置头 使可以跨域访问
//             * @param registry
//             * @since 4.2
//             */
//            @Override
//            public void addCorsMappings(CorsRegistry registry) {
//                registry.addMapping("/**")
//                        .allowedOrigins("*")
//                        .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
//                        .maxAge(3600)
//                        .allowCredentials(true);
//            }
//        };
//    }

}
